package service.impl;

import java.util.List;

import model.Assessor;
import model.User;
import dao.AssessorDao;
import service.AssessorManager;

public class AssessorManagerImpl implements AssessorManager {
	private AssessorDao assessorDao;
	public AssessorDao getAssessorDao() {
		return assessorDao;
	}
	public void setAssessorDao(AssessorDao assessorDao) {
		this.assessorDao = assessorDao;
	}
	public int addAssessorManager(String user, String pass, String realName,
			int gender, int tech, String tel, String email,int power) throws Exception {
		// TODO Auto-generated method stub
		try {
			Assessor a = new Assessor();
			a.setUser(user);
			a.setPass(pass);
			a.setRealName(realName);
			a.setGender(gender);
			a.setTech(tech);
			a.setTel(tel);
			a.setEmail(email);
			a.setPower(power);
			assessorDao.save(a);
			return a.getId();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			throw new Exception("新增评审员信息时出现异常");
		}
	}
	public int loginValid(String user, String pass) throws Exception {
		// TODO Auto-generated method stub
		try {
			Assessor a = assessorDao.findUserByNameAndPass(user, pass);
			if (a != null) {
				return a.getId();
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception("验证用户登录时出现异常");
		}
		return -1;
	}
	public Assessor getUser(int id) throws Exception {
		// TODO Auto-generated method stub
		try {
			Assessor a = assessorDao.get(id);
			return a;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			throw new Exception("查找用户时出现异常");
		}	
	}
	public List<Assessor> getAssessorByTech(int tech) throws Exception{
		try {
			List<Assessor> assessors = assessorDao.getAssessorByTech(tech);
			return assessors;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			throw new Exception("按专业方向查找用户时出现异常");
		}
	}
}
